var _ = require('lodash'),
    entityCollection = require('../../../Base/server/controllers/EntityCollection');

//根据编码查找扩展枚举
exports.findByCode = function(enumCode, completeFun){
	var extendEnumEntity = entityCollection.getEntity("ExtendEnum");
	extendEnumEntity.findOne({Code: enumCode}, null, function(err, record){
		completeFun(err, record);
	});
};

//根据编码查找扩展枚举
exports.findEnumOptions = function(enumCode, completeFun){
    var extendEnumEntity = entityCollection.getEntity("ExtendEnum");
    extendEnumEntity.findOne({Code: enumCode}, null, function (err, record) {
        if (err || !record) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询扩展枚举错误';
            if (err) {
                newErr.message = '查询失败，请检查查询参数！';
            }
            if (!record) {
                newErr.message = '没有找到对应的扩展枚举，请检查查询参数！';
            }
            completeFun(newErr);
            return;
        }
        var result = {};
        _.forEach(record.Options, function (option) {
            result[option.Value] = option.Name;
        });
        completeFun(null, result);
    });
};